<%@include file="top.jsp"%>
<jsp:useBean id="user" class="mvc.User" scope="session" />
<%
// Get data from user bean
String username = user.getUsername();

// No username = no user in session = not logged in
if(username.equals(""))
out.println("You have to log in to see this page!<br><a href=\"/mvcjsp/login.jsp\">To Login Page");
else{
out.println("Logged in as " + username + "<br><a href=\"/servlet/mvc.Servl?state=logout\">Logout</a>");
%>
<jsp:useBean id="gb" type="mvc.Guestbook" scope="session" />
<center>
	<table width="560" border="0">
		<tr>
	      <td><h3>MayClub GuestBook</h3><hr style="border:dashed #676767; border-width:1px 0 0 0; height:1;"></td>
	    </tr>
	</table>
<form name="form1" method="post" action="/servlet/mvc.Servl?state=guestbook&update">
<table width="560" border="0">
   <tr>
      <td align="left" valign="top">
	<textarea name="textarea"></textarea>
	<%if(request.getAttribute("errorMessage")!=null)
	out.println(request.getAttribute("errorMessage"));%><br>
      <input type="submit" name="Submit" value="Post"></form></td>
    </tr>
</table>
<table width="560" border="0">
	<tr>
      <td width="560"><hr style="border:dashed #676767; border-width:1px 0 0 0; height:1;"></td>
    </tr>
</table>
<table width="560" border="0">
<%
// Get data from gb bean
int pageCount = gb.getPageCount();
int totalPages = gb.getTotalpages();
Iterator<GbPost> it = gb.getAllGbPosts();

// Loop
while(it.hasNext()){
GbPost a = it.next();
%>
<tr>
	<td style="WORD-BREAK:BREAK-ALL" align="left">
	<b>Posted by </b><a href="/servlet/mvc.Servl?state=profile&profile=<%=a.getUsername()%>"><%=a.getUsername()%></a> 
	<%if(a.getUsername().equals(username) || user.isAdmin()) {%>
	- <a href="/servlet/mvc.Servl?state=guestbook&remove=<%=a.getId()%>">remove</a><%}%>
	<br>	
	<%=a.getText()%>
	<br><hr style="border:dashed #676767; border-width:1px 0 0 0; height:1;">	
	</td>
</tr>
<%}// For the navigator
String inc = "guestbook";%>
</table>
<%@include file="navigator.jsp"%>
<%}%>
</center>
<%@include file="bottom.jsp"%>

